/*
 *
 *      Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the pig4cloud.com developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: lengleng (wangiegie@gmail.com)
 *
 */

package com.pig4cloud.pigx.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.admin.api.entity.OverallDownstream;
import com.pig4cloud.pigx.admin.api.entity.OverallInfrastructure;
import com.pig4cloud.pigx.admin.api.entity.OverallRegimenStation;
import com.pig4cloud.pigx.admin.mapper.OverallDownstreamMapper;
import com.pig4cloud.pigx.admin.mapper.OverallInfrastructureMapper;
import com.pig4cloud.pigx.admin.mapper.OverallRegimenStationMapper;
import com.pig4cloud.pigx.admin.service.OverallDownstreamService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 四全下游要素 服务实现类
 * </p>
 *
 * @author lengleng
 * @since 2018-01-20
 */
@Service
@AllArgsConstructor
public class OverallDownstreamServiceImpl extends ServiceImpl<OverallDownstreamMapper, OverallDownstream> implements OverallDownstreamService {


    private final OverallDownstreamMapper mapper;

    private final OverallInfrastructureMapper infrastructureMapper;

    private final OverallRegimenStationMapper regimenStationMapper;


    /**
     *
     * @param type
     * @return OverallDownstream
     * @author lfx
     * @date 2024/8/12 14:54
     * @Desc 四全下游要素查询接口
     **/
    @Override
    public OverallDownstream queryStatistics(String type) {
        if(StringUtils.isEmpty(type)){
            return null;
        }
        OverallDownstream overallDownstream = mapper.selectOne(Wrappers.lambdaQuery(OverallDownstream.class)
                .eq(OverallDownstream::getType, type));
        // 查询基础设施数量
        Long infrastructureNum = infrastructureMapper.selectCount(Wrappers.lambdaQuery(OverallInfrastructure.class));
        // 查询水文站数量
        Long downstreamStationNum = regimenStationMapper.selectCount(Wrappers.lambdaQuery(OverallRegimenStation.class));
        overallDownstream.setDownstreamStation(downstreamStationNum.intValue())
                .setInfrastructure(infrastructureNum.intValue());
        return overallDownstream;
    }
}
